<template>
  <div class="counter-container">
    <h2>计数器示例</h2>
    <p id="counter" ref="counterRef">{{ count }}</p>
    <button @click="increment">增加计数</button>
  </div>
</template>

<script setup>
import { ref, nextTick } from 'vue'

const count = ref(0)
const counterRef = ref(1)

const increment = async () => {
  count.value++

  await nextTick()
  console.log('最新的数据：', count.value)
  console.log('通过DOM拿textContent数据：', counterRef.value.textContent)
  console.log('通过DOM拿textContent数据：', document.getElementById('counter').textContent)
  console.log('通过DOM拿innerHTML数据：', counterRef.value.innerHTML)
  console.log('通过DOM拿innerHTML数据：', document.getElementById('counter').innerHTML)
}
</script>
<style scoped>
.counter-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px;
  width: 300px;
  margin: 50px auto;
  background-color: #f9f9f9;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

h2 {
  font-size: 1.5em;
  margin-bottom: 10px;
  color: #333;
}

p {
  font-size: 1.2em;
  margin-bottom: 20px;
  color: #666;
}

button {
  padding: 10px 20px;
  font-size: 1em;
  color: white;
  background-color: #42b983;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button:hover {
  background-color: #36a572;
}
</style>
